package com.sf.dlb.web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sf.dlb.bean.ETHWalletRequestBean;
import com.sf.dlb.bean.SysUserRquestBean;
import com.sf.dlb.bean.UserListRequestBean;
import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.jpa.model.*;
import com.sf.dlb.jpa.repository.*;
import com.sf.dlb.mapper.dao.NewRecodMapper;
import com.sf.dlb.mapper.dao.UserInfoMapper;
import com.sf.dlb.mapper.entity.NewRecodListEntity;
import com.sf.dlb.mapper.entity.UserFriendListEntity;
import com.sf.dlb.mapper.entity.UserReaderNewClassEntity;
import com.sf.dlb.service.BaseWalletEthAddressService;
import com.sf.dlb.utils.*;
import com.sf.dlb.vo.*;
import com.sf.dlb.web.config.Global;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;

/**
 * Created by jing.tan on 2018/12/10.
 */
@Service
public class SysUserService {
    private static Logger logger= LoggerFactory.getLogger(SysUserService.class);

    @Autowired
    private SysUserRepository sysUserRepository;
    @Autowired
    private UserInfoRepository userInfoRepository;
    @Autowired
    private UserWalletRepository userWalletRepository;
    @Autowired
    private NewRecodMapper newRecodMapper;
    @Autowired
    private UserRealInfoRepository userRealInfoRepository;
    @Autowired
    private UserNewRepository userNewRepository;
    @Autowired
    private WalletExtractRepository walletExtractRepository;
    @Autowired
    private BaseWalletEthAddressService walletEthAddressService;
    @Autowired
    private BackThreadService backThreadService;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Resource
    private Global global;
    /**
     * 密码登录
     * @param sysuserRquestBean
     * @return
     */
    public ResultVO loginPasswrod(SysUserRquestBean sysuserRquestBean){
        logger.info("==loginPasswrod start sysuserRquestBean={}",GsonUtils.getInstance().toJson(sysuserRquestBean));
        SysUserInfo sysuserInfo=sysUserRepository.findByLoginNameAndDelFlag(sysuserRquestBean.getLoginName(), BaseEntity.DEL_FLAG);
        if(null==sysuserInfo){
            return ResultVOUtil.error(ResponseConstant.ERROR,"此用户不存在");
        }
        //校验密码
        boolean validatePassword=SecurityUtils.validatePassword(sysuserRquestBean.getPassword(),sysuserInfo.getPassword());
        if(validatePassword){
            //生成token
            TokenEntity tokenEntity=generaAndSaveToken(sysuserInfo.getId()+"",DateUtils.formatDate(new Date()));
            logger.info("loginPasswrod token == "+GsonUtils.getInstance().toJson(tokenEntity));
            SysUserVO sysuserVO=userBeanToVo(sysuserInfo,tokenEntity);
            return ResultVOUtil.success(sysuserVO);
        }else{
            return ResultVOUtil.error(ResponseConstant.ERROR,"密码错误");
        }
    }
    /**
     * 生成并保存token
     *
     * @param userId
     * @param createDate
     * @return
     */
    public TokenEntity generaAndSaveToken(String userId,String createDate){
        String uuid=UUID.randomUUID().toString().replace("-","");
        TokenEntity tokenEntity=generaToken(userId,createDate,uuid);
        SysUserInfo sysuserInfo = sysUserRepository.findByIdAndDelFlag(Long.valueOf(tokenEntity.getUserId()),"0");
        sysuserInfo.setToken(tokenEntity.getToken());
        sysuserInfo.setTokenTime(tokenEntity.getCreateDate());
        sysuserInfo.setUpdateDate(new Date());
        sysUserRepository.save(sysuserInfo);
        return tokenEntity;
    }
    /**
     * 生成toekn
     *
     * @param userId
     * @param createDate
     * @return
     */
    public TokenEntity generaToken(String userId,String createDate,String uuid){
        TokenEntity tokenEntity=new TokenEntity();
        String token=MD5Util.MD5(userId+createDate+uuid);
        tokenEntity.setToken(token);
        tokenEntity.setCreateDate(new Date());
        tokenEntity.setExpiresIn(Long.valueOf(global.token_valid_time));
        tokenEntity.setUserId(userId);
        return tokenEntity;
    }
    /**
     * 获取用户列表
     * @param userListRquestBean
     * @return
     */
    public ResultVO getUserList(UserListRequestBean userListRquestBean){
        logger.info("getUserList start userListRquestBean={}", GsonUtils.getInstance().toJson(userListRquestBean));
        int page=userListRquestBean.getCurrentPages();
        int size=userListRquestBean.getPageSize();
        String userId=userListRquestBean.getUserId();
        String mobile=userListRquestBean.getMobile();
        String name=userListRquestBean.getName();
        String realState=userListRquestBean.getRealState();
        PageHelper.startPage(page,size);
        List<UserInfo> userInfoList=userInfoMapper.queryUserInfoList(userId,mobile,name,realState);
        PageInfo<UserInfo> pageInfo=new PageInfo<>(userInfoList);
        //封装VO
//        List<UserInfo> userInfoList=userInfoPageInfo.getList();
        List<UserListVO> userVOS=new ArrayList<>();
        for (UserInfo userInfo1:userInfoList) {
            UserListVO userListVO=new UserListVO();
            userListVO.setUserId(userInfo1.getUserId());
            userListVO.setMobile(userInfo1.getMobile());
            userListVO.setName(userInfo1.getName());
            userListVO.setQrCode(userInfo1.getQrCode());
            userListVO.setLoginFlag(userInfo1.getLoginFlag());
            userListVO.setLoginFlagValue(StateToValueUtils.switchLoginFlagValue(userInfo1.getLoginFlag()));
            //实名认证状态
            UserRealInfo userRealInfo=userRealInfoRepository.findByUserIdAndDelFlag(userInfo1.getUserId(),"0");
            String tempRealState=(null!=userRealInfo?userRealInfo.getState():"1");
            userListVO.setRealState(tempRealState);
            userListVO.setRealStateValue(StateToValueUtils.switchRealStateValue(userListVO.getRealState()));
            //统计收益数据
            handlerCountEarningData(userInfo1,userListVO);
            userListVO.setCreateDate(userInfo1.getCreateDate().getTime());
            userListVO.setRegisterDayNumber((int)DateUtils.pastDays(userInfo1.getCreateDate()));
            userVOS.add(userListVO);
        }
        PageVO pageVO=new PageVO();
        pageVO.setDataList(userVOS);
        pageVO.setPageSize(size);
        pageVO.setCurrentPages(page);
        pageVO.setFirstPage((!pageInfo.isHasPreviousPage()));
        pageVO.setLastPage((!pageInfo.isHasNextPage()));
        pageVO.setTotalElements(pageInfo.getTotal());
        pageVO.setTotalPages(pageInfo.getPages());
        return ResultVOUtil.success(pageVO);
    }
    /**
     * 统计用户总收益数据
     */
    private void handlerCountEarningData(UserInfo userInfo,UserListVO userListVO) {
        UserNewInfo userNewInfo=userNewRepository.findByUserIdAndDelFlag(userInfo.getUserId(),"0");
        UserWalletInfo userWalletInfo=userWalletRepository.findByUserIdAndDelFlag(userInfo.getUserId(),"0");
        Integer newCountTime=0;
        Integer newReadCount=0;
        Double getDlbCount=0.0;
        Double lockDlb=0.0;
        Double unlockDlb=0.0;
        Double availableDlb=0.0;
        Double walletCount=0.0;
//      用户钱包可能为空，用户钱包某个字段可能为空
        if(userNewInfo!=null){
            newCountTime=(userNewInfo.getReadTimeLong()==null?0: userNewInfo.getReadTimeLong());
            getDlbCount=(userNewInfo.getHistoryGetdlbCount()==null?0:userNewInfo.getHistoryGetdlbCount());
            newReadCount=(userNewInfo.getReadCount()==null?0:userNewInfo.getReadCount());
            lockDlb=(userWalletInfo.getLockDlb()==null?0:userWalletInfo.getLockDlb());
            unlockDlb=(userWalletInfo.getUnlockDlb()==null?0:userWalletInfo.getUnlockDlb());
            availableDlb=(userWalletInfo.getAvailableDlb()==null?0:userWalletInfo.getAvailableDlb());
            walletCount=Arith.add(Arith.add(lockDlb,unlockDlb),availableDlb);
        }
        StringBuffer stringBuffer=new StringBuffer()
                .append("newCountTime=").append(newCountTime).append(" & ")
                .append("getDlbCount=").append(getDlbCount).append(" & ")
                .append("newReadCount=").append(newReadCount).append(" & ")
                .append("lockDlb=").append(lockDlb).append(" & ")
                .append("unlockDlb=").append(unlockDlb).append(" & ")
                .append("availableDlb=").append(availableDlb).append(" & ")
                .append("walletCount=").append(walletCount).append(" & ");
        logger.info("handlerCountEarningData stringBuffer is "+stringBuffer.toString());

        userListVO.setReadTimeCount(newCountTime);
        userListVO.setReadNumberCount(newReadCount);
        userListVO.setReadGetdlbCount(StringFormatUtils.kill3Decimals(getDlbCount));
        userListVO.setLockDlb(StringFormatUtils.kill3Decimals(lockDlb));
        userListVO.setUnlockDlb(StringFormatUtils.kill3Decimals(unlockDlb));
        userListVO.setAvailableDlb(StringFormatUtils.kill3Decimals(availableDlb));
        userListVO.setWalletCount(StringFormatUtils.kill3Decimals(walletCount));
    }

    /**
     * 获取用户好友收益行为
     * @param userListRquestBean
     * @return
     */
    public ResultVO getUserFriendList(UserListRequestBean userListRquestBean){
        String userId=userListRquestBean.getUserId();
        int page=userListRquestBean.getCurrentPages();
        int size=userListRquestBean.getPageSize();
        PageHelper.startPage(page,size);
        //这个用户邀请了那些好友
        //查询出这些好友的收益信息
        //对这些信息进行分页
        List<UserFriendListEntity> userFriendBalance= newRecodMapper.findByUserFriendBalance(userId);
        PageInfo<UserFriendListEntity> pageInfo= new PageInfo<>(userFriendBalance);
        //封装VO
        List<UserListVO> userListVOS=new ArrayList<>();
        for (UserFriendListEntity userFriendListEntity:userFriendBalance) {
            UserListVO userListVO=new UserListVO();
            userListVO.setUserId(userFriendListEntity.getInvitationUserId());
            userListVO.setName(userFriendListEntity.getName());
            userListVO.setMobile(userFriendListEntity.getMobile());
            userListVO.setCreateDate(userFriendListEntity.getCreateDate().getTime());
            userListVO.setReadTimeCount(userFriendListEntity.getReadTimeLong());
            userListVO.setReadNumberCount(userFriendListEntity.getReadCount());
            userListVO.setReadGetdlbCount(StringFormatUtils.kill3Decimals(userFriendListEntity.getHistoryGetdlbCount()));
            userListVO.setWalletCount(StringFormatUtils.kill3Decimals(userFriendListEntity.getWalletCount()));
            userListVOS.add(userListVO);
        }
        PageVO pageVO=new PageVO();
        pageVO.setDataList(userListVOS);
        pageVO.setPageSize(size);
        pageVO.setCurrentPages(page);
        pageVO.setFirstPage((!pageInfo.isHasPreviousPage()));
        pageVO.setLastPage((!pageInfo.isHasNextPage()));
        pageVO.setTotalElements(pageInfo.getTotal());
        pageVO.setTotalPages(pageInfo.getPages());
        return ResultVOUtil.success(pageVO);
    }
    /**
     * 处理用户每个分类阅读时长阅读数量
     * @param newRecodListEntity
     * @param userNewListVO
     */
    private void handlerReaderNewClass(NewRecodListEntity newRecodListEntity, UserNewListVO userNewListVO) {
        String userId=newRecodListEntity.getUserId();
        String everyDayDate=newRecodListEntity.getEveryDayDate();
        List<UserReaderNewClassEntity> userReaderNewClassEntities= newRecodMapper.findByUserReaderNewClassStatistic(userId,everyDayDate,"0","1");
        if(CollectionUtils.isEmpty(userReaderNewClassEntities)){
            logger.info("handlerReaderNewClass userReaderNewClassEntities is null");
            return;
        }
        List<UserNewListVO.NewClassBean> newClassDate=new ArrayList();
        for (UserReaderNewClassEntity userReaderNewClassEntity:userReaderNewClassEntities) {
            UserNewListVO.NewClassBean newClassBean=new UserNewListVO.NewClassBean();
            newClassBean.setId(userReaderNewClassEntity.getClassId());
            newClassBean.setName(userReaderNewClassEntity.getNewClassName());
            newClassBean.setReaderNumber(userReaderNewClassEntity.getReaderNumber());
            newClassBean.setReaderTime(userReaderNewClassEntity.getReaderTime());
            newClassDate.add(newClassBean);
        }
        userNewListVO.setNewClassDate(newClassDate);
    }
    /**
     * 获取用户好友收益
     * @param userListRquestBean
     * @return
     */
    public ResultVO getUserReaderList(UserListRequestBean userListRquestBean){
        String userId=userListRquestBean.getUserId();
        int page=userListRquestBean.getCurrentPages();
        int size=userListRquestBean.getPageSize();
        PageHelper.startPage(page,size);
        UserInfo userInfo=userInfoRepository.findByUserIdAndDelFlag(userId,"0");
        List<NewRecodListEntity> newRecodListEntities= newRecodMapper.findByUserReaderBehaviourStatistic(userId,"0","1");
        logger.info("getUserReaderList newRecodListEntities is "+newRecodListEntities.size());
        PageInfo<NewRecodListEntity> pageInfo= new PageInfo<>(newRecodListEntities);
        //封装VO
        List<UserNewListVO> userListVOS=new ArrayList<>();
        for (NewRecodListEntity newRecodListEntity:newRecodListEntities) {
            UserNewListVO userNewListVO=new UserNewListVO();
            userNewListVO.setUserId(userId);
            userNewListVO.setName(userInfo.getName());
            userNewListVO.setEveryDayReadNumer(newRecodListEntity.getEveryDayReadNumer());
            userNewListVO.setEveryDayReadTime(newRecodListEntity.getEveryDayReadTime());
            userNewListVO.setEveryDayDlb(StringFormatUtils.kill3Decimals(newRecodListEntity.getEveryDayDlb()));
            long everyDayDateL=new Date().getTime();
            try {
                everyDayDateL=DateUtils.parseDate(newRecodListEntity.getEveryDayDate(), "yyyy-MM-dd").getTime();
            }catch (Exception e){
                e.printStackTrace();
                logger.info("getUserReaderList everyDayDateL is errer");
            }
            userNewListVO.setEveryDayDate(everyDayDateL);
            handlerReaderNewClass(newRecodListEntity,userNewListVO);//分类阅读详情
            userListVOS.add(userNewListVO);
        }
        PageVO pageVO=new PageVO();
        pageVO.setDataList(userListVOS);
        pageVO.setPageSize(size);
        pageVO.setCurrentPages(page);
        pageVO.setFirstPage((!pageInfo.isHasPreviousPage()));
        pageVO.setLastPage((!pageInfo.isHasNextPage()));
        pageVO.setTotalElements(pageInfo.getTotal());
        pageVO.setTotalPages(pageInfo.getPages());
        return ResultVOUtil.success(pageVO);
    }
    /**
     * 根据Token查找用户
     *
     * @param tokenEntity
     * @return
     */
    public ResultVO findByUserAndToken(NewRecodListEntity newRecodListEntity, TokenEntity tokenEntity){
        logger.info("findByUserAndToken tokenEntity "+GsonUtils.getInstance().toJson(tokenEntity));
        String userId=tokenEntity.getUserId();
        SysUserInfo sysuserInfo=sysUserRepository.findByIdAndDelFlag(Long.valueOf(userId),"0");
        SysUserVO sysUserVO=userBeanToVo(sysuserInfo,tokenEntity);
        return ResultVOUtil.success(sysUserVO);
    }
    /**
     * 检验token
     * @param token
     * @return
     */
    public ResultVO checkoutToken(String token){
        //token是否存在
        SysUserInfo sysuserInfo = sysUserRepository.findByTokenAndDelFlag(token,"0");
        if(null==sysuserInfo){
            return ResultVOUtil.error(ResponseConstant.ERROR_TOKEN_THERE_NO, "账号在其他地方登录");
        }
        TokenEntity tokenEntity=new TokenEntity();
        tokenEntity.setUserId(sysuserInfo.getId()+"");
        tokenEntity.setToken(sysuserInfo.getToken());
        tokenEntity.setCreateDate(sysuserInfo.getTokenTime());
        tokenEntity.setExpiresIn(Long.valueOf(global.token_valid_time));
        //toKen是否过期
        Date createDate=sysuserInfo.getTokenTime();
        Date currntDate=new Date();
        Long expiresIn=Long.valueOf(global.token_valid_time);
        long timeDifference=(currntDate.getTime()-createDate.getTime())/1000;
        if(timeDifference>expiresIn) {
            logger.info("token已过期");
            return ResultVOUtil.error(ResponseConstant.ERROR_TOKEN_OVERDUE, "token已过期");
        }
        return ResultVOUtil.success(tokenEntity);
    }


    /**
     * 用户实名认证列表
     */
    public ResultVO userRealInfoList(UserListRequestBean userListRquestBean){
        UserRealInfo userRealInfo=new UserRealInfo();
        userRealInfo.setDelFlag("0");
        if(StringUtils.isNotBlank(userListRquestBean.getName())){
            userRealInfo.setName(userListRquestBean.getName());
        }
        if(StringUtils.isNotBlank(userListRquestBean.getIdNumber())){
            userRealInfo.setIdNumber(userListRquestBean.getIdNumber());
        }
        if(StringUtils.isNotBlank(userListRquestBean.getRealState())){
            userRealInfo.setState(userListRquestBean.getRealState());
        }
        Example example=Example.of(userRealInfo);
        int page=userListRquestBean.getCurrentPages();
        int size=userListRquestBean.getPageSize();
        Sort sort=new Sort(Sort.Direction.DESC,"createDate");
        Pageable pageable=new PageRequest(page,size,sort);
        Page pageAll=userRealInfoRepository.findAll(example,pageable);
        //封装VO
        List<UserRealInfo> userRealInfos=pageAll.getContent();
        List<UserRealVO> userRealVOS=new ArrayList<>();
        for (UserRealInfo userRealInfo1:userRealInfos) {
            UserRealVO userRealVO=new UserRealVO();
            BeanUtils.copyProperties(userRealInfo1,userRealVO);
            userRealVO.setIdNumberTypeValue(StateToValueUtils.switchIdNumberTypeValue(userRealInfo1.getIdNumberType()));
            userRealVO.setIdNumberImage(StateToValueUtils.realImageAddProfix(userRealInfo1.getIdNumberImage(),global.file_public_ip));
            userRealVO.setStateValue(StateToValueUtils.switchRealStateValue(userRealInfo1.getState()));
            userRealVO.setCreateDate(userRealInfo1.getCreateDate().getTime());
            UserInfo userInfo=userInfoRepository.findByUserIdAndDelFlag(userRealInfo1.getUserId(),"0");
            userRealVO.setNickname(userInfo.getName());
            userRealVOS.add(userRealVO);
        }
        PageVO pageVO=new PageVO();
        pageVO.setDataList(userRealVOS);
        pageVO.setPageSize(size);
        pageVO.setCurrentPages(page+1);//默认从0开始，返回前端要+1;
        pageVO.setFirstPage(pageAll.isFirst());
        pageVO.setLastPage(pageAll.isLast());
        pageVO.setTotalElements(pageAll.getTotalElements());
        pageVO.setTotalPages(pageAll.getTotalPages());
        return ResultVOUtil.success(pageVO);
    }
    /**
     * 用户实名认证状态更新
     * @return
     */
    public ResultVO updateUserRealState(UserListRequestBean reqeustData){
        logger.info("==updateUserRealState start reqeustData={}",GsonUtils.getInstance().toJson(reqeustData));
        String userId=reqeustData.getUserId();
        String realState=reqeustData.getRealState();
        String remarks=reqeustData.getRejectDesc();
        UserRealInfo userRealInfo=userRealInfoRepository.findByUserIdAndDelFlag(userId,"0");
        if(null==userRealInfo){
            logger.info("updateUserRealState 暂无实名认证信息");
            return ResultVOUtil.error(ResponseConstant.ERROR,"暂无实名认证信息");
        }
        userRealInfo.setState(realState);
        if(StringUtils.isNotBlank(remarks)){
            userRealInfo.setRejectDesc(remarks);
        }
        userRealInfo.setUpdateDate(new Date());
        userRealInfoRepository.save(userRealInfo);
        return ResultVOUtil.success();
    }
    /**
     * 查询提现列表
     *
     */
    public ResultVO extractList(String state,int page,int size){
        WalletExtractInfo walletExtractInfo=new WalletExtractInfo();
        walletExtractInfo.setDelFlag("0");
        if(StringUtils.isNotBlank(state)){
            walletExtractInfo.setExtractState(state);
        }
        Example example=Example.of(walletExtractInfo);
        Sort sort=new Sort(Sort.Direction.DESC,"createDate");
        Pageable pageable=new PageRequest(page,size,sort);
        Page<WalletExtractInfo> pageAll=walletExtractRepository.findAll(example,pageable);
        //封装VO
        List<WalletExtractInfo> walletExtractInfos=pageAll.getContent();
        List<WalletExtractVO> walletExtractVOS=new ArrayList<>();
        for (WalletExtractInfo walletExtractInfo1:walletExtractInfos) {
            WalletExtractVO walletExtractVO=new WalletExtractVO();
            BeanUtils.copyProperties(walletExtractInfo1,walletExtractVO);
            walletExtractVO.setExtractStateValue(StateToValueUtils.switchExtractStateValue(walletExtractInfo1.getExtractState()));
            walletExtractVO.setExtractTime(walletExtractInfo1.getCreateDate().getTime());
            UserInfo userInfo=userInfoRepository.findByUserIdAndDelFlag(walletExtractInfo1.getUserId(),"0");
            walletExtractVO.setNickname((null==userInfo?"":userInfo.getName()));
            walletExtractVOS.add(walletExtractVO);
        }
        PageVO pageVO=new PageVO();
        pageVO.setDataList(walletExtractVOS);
        pageVO.setPageSize(size);
        pageVO.setCurrentPages(page+1);//默认从0开始，返回前端要+1;
        pageVO.setFirstPage(pageAll.isFirst());
        pageVO.setLastPage(pageAll.isLast());
        pageVO.setTotalElements(pageAll.getTotalElements());
        pageVO.setTotalPages(pageAll.getTotalPages());
        return ResultVOUtil.success(pageVO);
    }
    /**
     * 提现失败-重新提交
     *
     */
    public ResultVO extractResend(String extractNumber){
        logger.info("==extractResend start extractNumber={}",extractNumber);
        WalletExtractInfo walletExtractInfo=walletExtractRepository.findByExtractNumberAndDelFlag(extractNumber,"0");
        if(null==walletExtractInfo){
            logger.info("==extractResend null==walletExtractInfo ");
            return ResultVOUtil.error(ResponseConstant.ERROR,"提现数据不存在");
        }
        //重新提交的状态必须是提现中的
        if(!walletExtractInfo.getExtractState().equals("1")){
            logger.info("extractResend !walletExtractInfo.getExtractState().equals(1)");
            return ResultVOUtil.error(ResponseConstant.ERROR,"此数据不能重新提交");
        }
        //查账户在以太坊是否已经打包成功，提现中的数据都是没有hash码-》多余操作
        //查询队列中是否还存在此任务
        ArrayList<ETHWalletRequestBean> ethWalletRequestBeans=backThreadService.queueConsumerList;
        for (ETHWalletRequestBean ethWalletRequestBean:ethWalletRequestBeans) {
            if(ethWalletRequestBean.getSerialNumber().equals(walletExtractInfo.getExtractNumber())){
                logger.info(" == extractResend 队列中还存在此任务");
                return ResultVOUtil.error(ResponseConstant.ERROR,"队列中还存在此任务");
            }
        }
        //公司账户
        WalletEthAddressInfo walletEthAddressInfo=walletEthAddressService.getCompanyETHAdress();//获取公司账户
        if(null==walletEthAddressInfo){
            logger.info("extractDlb null==walletEthAddressInfo ");
            return ResultVOUtil.error(ResponseConstant.ERROR,"暂时无法提现");
        }
        //加入队列@TODO 这里需要在前端项目里，把队列改成redis
        try {
//            ETHWalletRequestBean ethWalletRequestBean=new ETHWalletRequestBean();
//            ethWalletRequestBean.setUserId(walletExtractInfo.getUserId());
//            ethWalletRequestBean.setSerialNumber(walletExtractInfo.getExtractNumber());
//            ethWalletRequestBean.setToAddress(walletExtractInfo.getExtractAddress());
//            //提现额度(包含了手续费)，应该减去手续费
//            Double extractCount=walletExtractInfo.getExtractCount();
//            Double extractCharge=walletExtractInfo.getExtractCharge();
//            ethWalletRequestBean.setCount((int)(Arith.sub(extractCount,extractCharge)));
//            ethWalletRequestBean.setFromAddress(walletEthAddressInfo.getAddress());
//            ethWalletRequestBean.setPrivateKey(walletEthAddressInfo.getPrivateKey());
//            backThreadService.queueConsumer.put(ethWalletRequestBean);
//            backThreadService.queueConsumerList.add(ethWalletRequestBean);
        }catch (Exception e){
            e.printStackTrace();
            logger.info("== extractDlb backThreadService.queueConsumer.put errer");
        }
        return ResultVOUtil.success();
    }
    /**
     * 4-用户抽成明细表
     */
    public ResultVO userDlbDetails(){
        logger.info("==userDlbDetails start");

        logger.info("==userDlbDetails end");
        return ResultVOUtil.success();
    }
    /**
     * VO转换
     * @return
     */
    public SysUserVO userBeanToVo(SysUserInfo sysuserInfo, TokenEntity tokenEntity){
        SysUserVO sysuserVO=new SysUserVO();
        BeanUtils.copyProperties(sysuserInfo,sysuserVO);
        sysuserVO.setPhoto(StringUtils.isNotBlank(sysuserVO.getPhoto())?global.file_public_ip+sysuserVO.getPhoto():sysuserVO.getPhoto());
        sysuserVO.setToken(tokenEntity.getToken());
        return sysuserVO;
    }
}
